package com.kwin.demo.server.application.wrapper;

import com.kwin.demo.api.dto.resp.UserDTO;
import com.kwin.demo.server.domain.template.model.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author kwin
 * @Date 2022/1/19 14:16
 **/
@Mapper
public interface UserWrapper {
    UserWrapper INSTANCE = Mappers.getMapper(UserWrapper.class);

    @Mappings({
        @Mapping(source = "birthday", target = "birth"),
        @Mapping(source = "birthday", target = "birthDateFormat", dateFormat = "yyyy-MM-dd HH:mm:ss"),
        @Mapping(target = "sexStr", expression = "java(user.getSex() == 0 ? \"男\" : \"女\")"),
        @Mapping(source = "cardInfo.cardId", target = "cardId"),
        @Mapping(source = "cardInfo.type", target = "type"),
        @Mapping(target = "email", ignore = true)
    })
    UserDTO convertModel(User user);

    List<UserDTO> convert(List<User> users);
}
